import { Component, OnInit } from '@angular/core';
import { HttpClient } from '@angular/common/http';

@Component({
	selector: 'app-operation-record',
	templateUrl: './operation-record.component.html',
	styleUrls: ['./operation-record.component.scss']
})
export class OperationRecordComponent implements OnInit {
	messages = [];
	// 当前页面页脚信息
	currentPage: number = 1;
	pages: number;
	total: number;
	targetPage: number = 1;
	constructor(private http: HttpClient) { }
	/**
	 * 跳转页面
	 */
	goToPage(event) {
		const info = event.target.innerText;
		if (info === '上一页' && this.currentPage !== 1) {
			this.currentPage--;
		} else if (info === '下一页') {
			if (this.currentPage >= this.pages) {
				return;
			}
			this.currentPage++;
		} else if (info === 'Goto') {
			this.currentPage = this.targetPage;
		} else if (info === '首页') {
			this.currentPage = 1;
		} else if (info === '尾页') {
			this.currentPage = this.pages;
		} else {
			return;
		}
		// 这边到时候要加上一个获取list集合的请求
		this.obtainPatientList();
	}
	obtainPatientList() {
		const params: any = {
			// 这里填写用户信息及list集合，还需要当前页面的页脚等信息
			params: {
				order_by: '-create_time',
				current_page: this.currentPage,
				per_page: 20
			}
		};
		this.http.get(window.API_ROOT + 'api/recipes/handlerecords', params).subscribe((res: any) => {
			this.messages = res.data.results;
			this.pages = res.data.total_page;
			this.total = res.data.total_num;
		});
		// this.http.get(window.API_ROOT + 'api/recipes/' + 411 ).subscribe((res: any) => {
		// 	console.log('res_', res);
		//   });
	}
	ngOnInit() {
		this.obtainPatientList();
	}

}
